package com.ggs.rg.ybjb.adminmodule.util;

import com.alibaba.fastjson.JSONObject;
import com.ggs.rg.ybjb.pojomodule.pojo.TUser;
import org.springframework.beans.factory.annotation.Value;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * ClassName:UserUtil
 * Package:com.ggs.rg.ybjb.adminmodule.util
 * Description:
 * 用户工具类
 *
 * @Date:2021/11/6 10:06
 * @Author:cxw
 */
public class UserUtil {

    /**
     * 去除空信息,只给前端返回前端用到的信息的方法
     *
     * @param userData 从数据库中查询到的用户数据集合
     * @return List<JSONObject>
     */
    public static List<JSONObject> getResultList(List<TUser> userData) {
        List<JSONObject> resultList = new ArrayList<>();
        for (TUser tUser : userData) {
            String phone = tUser.getPhone();
            String name = tUser.getName();
            Boolean type = tUser.getType();
            Date createTime = tUser.getCreateTime();
            Date updateTime = tUser.getUpdateTime();
            JSONObject user = new JSONObject();
            user.put("phone", phone);
            user.put("name", name);
            user.put("createTime", createTime);
            user.put("updateTime", updateTime);
            if (type)
                user.put("type", "普通用户");
            else
                user.put("type", "超级管理员");
            resultList.add(user);
        }
        return resultList;
    }

    public static JSONObject getResultList(TUser tUser,String port) {
        String phone = tUser.getPhone();
        String name = tUser.getName();
        Boolean type = tUser.getType();
        Date createTime = tUser.getCreateTime();
        Date updateTime = tUser.getUpdateTime();
        String image = tUser.getImage();
        String imageAddr = ImageUtil.getImageAddr(image,port);
        String pDesc = tUser.getPDesc();
        String email = tUser.getEmail();
        Boolean sex = tUser.getSex();
        Double money = tUser.getMoney();
        JSONObject user = new JSONObject();
        user.put("phone", phone);
        user.put("name", name);
        user.put("createTime", createTime);
        user.put("updateTime", updateTime);
        user.put("imageAddr",imageAddr);
        user.put("pDesc",pDesc);
        user.put("email",email);
        user.put("money",money);
        if (type)
            user.put("type", "普通用户");
        else
            user.put("type", "超级管理员");
        if (sex)
            user.put("sex","女");
        else
            user.put("sex","男");
        return user;
    }

    public static JSONObject getResultList(TUser tUser,List list,String port) {
        String phone = tUser.getPhone();
        String name = tUser.getName();
        Boolean type = tUser.getType();
        Date createTime = tUser.getCreateTime();
        Date updateTime = tUser.getUpdateTime();
        String image = tUser.getImage();
        String imageAddr = ImageUtil.getImageAddr(image,port);
        String pDesc = tUser.getPDesc();
        String email = tUser.getEmail();
        Boolean sex = tUser.getSex();
        Double money = tUser.getMoney();
        JSONObject user = new JSONObject();
        user.put("phone", phone);
        user.put("name", name);
        user.put("createTime", createTime);
        user.put("updateTime", updateTime);
        user.put("imageAddr",imageAddr);
        user.put("pDesc",pDesc);
        user.put("email",email);
        user.put("money",money);
        if (type)
            user.put("type", "普通用户");
        else
            user.put("type", "超级管理员");
        if (sex)
            user.put("sex","女");
        else
            user.put("sex","男");
        user.put("orderList",list);
        return user;
    }
}
